package com.xinhe.web.controller;

import com.querydsl.core.QueryResults;
import com.xinhe.web.annotation.WebUsed;
import com.xinhe.web.common.Result;
import com.xinhe.web.response.TeamGoodsView;
import com.xinhe.web.service.TeamGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Set;

@Api(value = "拼团商品", tags = {"拼团商品"})
@RestController
@RequestMapping(value = {"/teamGoods"}, produces = {"application/json;charset=UTF-8"})

public class TeamGoodsController {
    @Autowired
    private TeamGoodsService teamGoodsService;

    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "分页查询拼团商品")
    @RequestMapping({"/pageTeamGoods"})
    public QueryResults<TeamGoodsView> pageTeamGoods(Long goodsId,Integer memberAmount,String remark,
                                                     String keyword,int pageNum, int pageSize) {
        return this.teamGoodsService.pageTeamGoods(goodsId,memberAmount, remark, keyword,pageNum,pageSize);
    }

    @WebUsed
    @ApiOperation(httpMethod = "POST", value = "保存拼团商品")
    @RequestMapping({"/saveTeamGoods"})
    public Result saveTeamGoods(Long id,Long goodsId, Integer memberAmount, String remark, String iconPath,
                                BigDecimal money, Set<Long> attachIds) {
        return this.teamGoodsService.saveTeamGoods(id,goodsId,memberAmount,remark,iconPath,money,attachIds);
    }

    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "删除拼团商品")
    @ApiImplicitParam(name = "teamGoodsId", value = "标识", dataTypeClass = Long.class, required = true)
    @RequestMapping({"/deleteTeamGoods"})
    public Result deleteTeamGoods(Long teamGoodsId) {
        return this.teamGoodsService.deleteTeamGoods(teamGoodsId);
    }

    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "拼团商品详情")
    @ApiImplicitParam(name = "teamGoodsId", value = "标识", dataTypeClass = Long.class, required = true)
    @RequestMapping({"/detailTeamGoods"})
    public Result<TeamGoodsView> detailTeamGoods(Long teamGoodsId) {
        return this.teamGoodsService.detailTeamGoods(teamGoodsId);
    }
}
